//
//  Fraction.m
//  Class4_属性
//
//  Created by rimi on 16/3/24.
//  Copyright © 2016年 DBF. All rights reserved.
//

#import "Fraction.h"
#import <math.h>
@implementation Fraction

-(void)setDenominatorr:(NSInteger)denominatorr
{
    if (denominatorr!=0) {
        _denominatorr=denominatorr;
    }
}

+ (void)addFirstFra:(Fraction*)fra1
               secondFra:(Fraction*)fra2
{
    NSInteger newmolecular=(fra1.molecular*fra2.denominatorr+fra2.molecular*fra1.denominatorr);
    NSInteger newdenominatorr=fra1.denominatorr*fra2.denominatorr;
    NSInteger count = 1;
    for (NSInteger i=1; i<=labs(newmolecular); i++) {
        if (labs(newmolecular)%i==0&&labs(newdenominatorr)%i==0) {
            if (count<i) {
                count = i;
            }
        }
    }
    newmolecular /= count;
    newdenominatorr /= count;
    NSLog(@"%ld/%ld",newmolecular,newdenominatorr);
}
+(void)minuFirstFra:(Fraction*)fra1
         secondFra:(Fraction*)fra2
{
    NSInteger newmolecular=(fra1.molecular*fra2.denominatorr-fra2.molecular*fra1.denominatorr);
    NSInteger newdenominatorr=fra1.denominatorr*fra2.denominatorr;
    NSInteger count = 1;
    for (NSInteger i=1; i<=labs(newmolecular); i++) {
        if ((labs(newmolecular)%i==0)&&labs(newdenominatorr)%i==0) {
            if (count<i) {
                count = i;
            }
        }
    }
    newmolecular /= count;
    newdenominatorr /= count;
    NSLog(@"%ld/%ld",newmolecular,newdenominatorr);
}

+(void)multiFirstFra:(Fraction*)fra1
           secondFra:(Fraction*)fra2
{
    NSInteger newmolecular=fra1.molecular*fra2.molecular;
    NSInteger newdenominatorr=fra1.denominatorr*fra2.denominatorr;
    NSInteger count = 1;
    for (NSInteger i=1; i<=labs(newmolecular); i++) {
        if ((labs(newmolecular)%i==0)&&labs(newdenominatorr)%i==0) {
            if (count<i) {
                count = i;
            }
        }
    }
    newmolecular /= count;
    newdenominatorr /= count;
    NSLog(@"%ld/%ld",newmolecular,newdenominatorr);
}

+(void)divisionFirstFra:(Fraction*)fra1
              secondFra:(Fraction*)fra2
{
    NSInteger newmolecular=fra1.molecular*fra2.denominatorr;
    NSInteger newdenominatorr=fra1.denominatorr*fra2.molecular;
    NSInteger count = 1;
    for (NSInteger i=1; i<=labs(newmolecular); i++) {
        if ((labs(newmolecular)%i==0)&&labs(newdenominatorr)%i==0) {
            if (count<i) {
                count = i;
            }
        }
    }
    newmolecular /= count;
    newdenominatorr /= count;
    NSLog(@"%ld/%ld",newmolecular,newdenominatorr);
}
@end
